var e = require("../@babel/runtime/helpers/interopRequireDefault").default;

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.SharePoster = void 0, exports.formatTimeStamp = function(e) {
    if (e <= 0) return {
        d: "00",
        h: "00",
        m: "00",
        s: "00"
    };
    var a = [ p, v, w, m ].reduce(function(t, a) {
        var n = Math.trunc(e / a);
        return t.push(n < 10 ? "0" + n : n), e %= a, t;
    }, []), n = t(a, 4), r = n[0], i = n[1], o = n[2], c = n[3];
    return {
        d: r,
        h: i,
        m: o,
        s: c
    };
}, exports.getQuery = g, exports.getUserInfo = void 0, exports.handleShare = function(e, t) {
    if (u.share(t), "190" === t || "record" === t) return {
        from: "button",
        title: "点这里！领80元话费",
        path: "/pages/webview/index?url=".concat(encodeURIComponent(e.data.shareUrl)),
        imageUrl: s.imageBaseUrl.YQYL + "shareImg_2.jpg"
    };
    if ("6" === t || "recordSpread" === t) return {
        from: "button",
        title: "亲测有效，参与这个活动可以赚钱！",
        path: "/pages/YQYL_homePage/index?spread_id=".concat(d.globalData.spread_id, "&channel=").concat(d.globalData.aucChannel, "&adtag=").concat(d.globalData.aucChannel),
        imageUrl: s.imageBaseUrl.YQYL2 + "shareImg.png"
    };
    if ("hf" === t) {
        var a = e.data.activity_info, n = a.nickname, r = a.invite_url, i = r && r.toLowerCase().includes("shareid");
        return {
            from: "button",
            title: i ? n ? "".concat(n, "送你一张超大流量卡") : "送你一张超大流量卡" : "快来领取200元话费",
            path: "/pages/webview/index?url=".concat(encodeURIComponent(r)),
            imageUrl: s.imageBaseUrl.YQYL_hf + "shareImg.png"
        };
    }
    if ("18" === t || "record18" === t) return {
        from: "button",
        title: "哇！恭喜你被话费红包砸中",
        path: "/pages/webview/index?url=".concat(encodeURIComponent(e.data.shareUrl)),
        imageUrl: s.imageBaseUrl.YQYL_new + "shareImg18.jpg"
    };
    throw new Error("未指定海报类型");
}, exports.initPage = function(e, t) {
    var a = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : "190";
    if (wx.showLoading({
        title: "加载中"
    }), d.globalData.aucChannel = g(t, "channel"), d.globalData.spread_id = g(t, "spread_id"), 
    "190" === a || "hf" === a) return h(e, a).then(function(t) {
        e.setData({
            isFinish: t.now >= t.end_time
        });
        var n = t.invite_url;
        return n && e.setData({
            shareUrl: n,
            postUtil: new f({
                type: a,
                vm: e,
                inviteUrl: n,
                nickname: t.nickname,
                profile_picture: t.profile_picture
            })
        }), t;
    }).finally(function() {
        wx.hideLoading();
    });
    if ("6" === a || "spreadRecord" === a) return i.default.getSpreadUserInfo().then(function(t) {
        t.result.reward_count = (t.result.reward_count / 100).toFixed(2), d.globalData.spread_id = t.result.spread_id;
        var n = "https://txwk.10010.com/KCard/mPages/YQYLRedirect.html?spread_id=".concat(t.result.spread_id, "&channel=").concat(d.globalData.aucChannel, "#/index");
        e.setData({
            shareUrl: n,
            result: t.result,
            postUtil: new f({
                type: a,
                inviteUrl: n,
                vm: e
            })
        });
    }).catch(function(t) {
        "32008" === t.code && (e.handleShowModal(), e.setData({
            isShowBtn: !1
        }));
    }).finally(function() {
        wx.hideLoading();
    });
    if ("18" === a || "record18" === a) return i.default.getUserInfo18().then(function(t) {
        var n = (t = t.data).shareInfo.url;
        return t.start_time = t.startTime, t.end_time = t.endTime, t.invite_succeed_count = t.successfulOrderCount || 0, 
        t.invite_rewarded_count = t.obtainMoney || 0, t.invite_url = n, t.nickname = t.nickName, 
        n && e.setData({
            shareUrl: n,
            postUtil: new f({
                type: a,
                vm: e,
                inviteUrl: n,
                nickname: t.nickname
            })
        }), e.setData({
            activity_info: t
        }), t;
    }).finally(function() {
        wx.hideLoading();
    });
    if ("dl" === a) return i.default.getUserInfo_dl().then(function(t) {
        (t = t.data).mainProgress = [ 0, 80, 85, 90, 95, 100 ][t.countToExtraReward], e.setData({
            userInfo: t,
            successRecordList: t.successUserMsg,
            inviteNum: t.countToExtraReward
        });
        var n = t.shareInfo.url;
        return n && e.setData({
            shareUrl: n,
            postUtil: new f({
                type: a,
                vm: e,
                inviteUrl: n,
                nickname: t.nickname
            })
        }), t;
    }).catch(function(t) {
        "10003" === t.code && e.setData({
            toastType1: "2"
        });
    }).finally(function() {
        wx.hideLoading();
    });
    return Promise.reject().then(function() {
        wx.hideLoading();
    });
}, exports.ktaUtil = void 0, exports.toHFRecordPage = function() {
    u.recordPage("hf"), wx.navigateTo({
        url: "/pages/YQYL_hf_record/index?channel=".concat(d.globalData.aucChannel, "&adtag=").concat(d.globalData.aucChannel)
    });
}, exports.toHFRulePage = function() {
    u.rulePage("hf"), wx.navigateTo({
        url: "/pages/webview/index?url=".concat(encodeURIComponent("https://txwk.10010.com/wkpen/view/dAF8C345c0.html"))
    });
}, exports.toHomePage2 = function(e) {
    e ? u.modalBtn() : u.headerBtn(), wx.navigateTo({
        url: "/pages/YQYL_homePage2/index?channel=".concat(d.globalData.aucChannel, "&adtag=").concat(d.globalData.aucChannel)
    });
}, exports.toRecord18Page = function() {
    u.recordPage(), wx.navigateTo({
        url: "/pages/YQYL_record18/index?channel=".concat(d.globalData.aucChannel, "&adtag=").concat(d.globalData.aucChannel)
    });
}, exports.toRecordPage = function() {
    u.recordPage(), wx.navigateTo({
        url: "/pages/YQYL_record/index?channel=".concat(d.globalData.aucChannel, "&adtag=").concat(d.globalData.aucChannel)
    });
}, exports.toRule18Page = function() {
    u.rulePage("18"), wx.navigateTo({
        url: "/pages/webview/index?url=".concat(encodeURIComponent("https://txwk.10010.com/wkpen/view/f9dAF7632d.html"))
    });
}, exports.toRulePage = function() {
    u.rulePage("190"), wx.navigateTo({
        url: "/pages/webview/index?url=".concat(encodeURIComponent("https://txwk.10010.com/wkpen/view/7625D8F713.html"))
    });
}, exports.toSpreadRecordPage = function() {
    u.recordPage("6"), wx.navigateTo({
        url: "/pages/YQYL_recordSpread/index?channel=".concat(d.globalData.aucChannel, "&adtag=").concat(d.globalData.aucChannel)
    });
}, exports.toSpreadRulePage = function() {
    u.rulePage("6"), wx.navigateTo({
        url: "/pages/webview/index?url=".concat(encodeURIComponent("https://txwk.10010.com/wkpen/view/0533b35d88.html"))
    });
};

var t = require("../@babel/runtime/helpers/slicedToArray"), a = require("../@babel/runtime/helpers/classCallCheck"), n = require("../@babel/runtime/helpers/createClass"), r = e(require("./Tips")), i = e(require("../api/api_YQYL")), o = e(require("../api/api_YQYL_hf")), c = e(require("../libs/qrcode/qrcode-edit")), s = require("../config/Links"), l = require("./util"), d = getApp(), u = {
    share: function(e) {
        return d.kta.clickStat({
            6: "68468ef9431342258b645fda49438e28",
            18: "f0dbc97b03e14bf0922d861ef55ffe2e",
            record18: "b73ab2be80f64b7ab933b5f4a406705c",
            190: "ff310d0b3d0f444da6cc07380f393646",
            record: "a0fa4621d0b14d0e94612d3863144d94",
            recordSpread: "9843f37f2d484aa6945ead529be4c114",
            hf: "643cc322595947268fba2072fbeda1a7"
        }[e]);
    },
    poster: function(e) {
        var t = {
            record: "a9375a18341148bfbb7765d6cb3528b6",
            spreadRecord: "6bac168d9294400bae02d3cbaeddf4e9",
            190: "1efcbc4e027b4014998057ef5f7162b4",
            6: "9a181fb2da404076bcac2503e10f24e2",
            18: "fbb6ab2e04094c0f97ac113b58624688",
            record18: "9f5a6d2dcc924e73a7e547e476f9bff4",
            hf: "34458a2e531b481c9e3782a108dd9ad8"
        };
        return t[e] ? d.kta.clickStat(t[e]) : "";
    },
    rulePage: function() {
        var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "190", t = {
            190: "8acbb838c5a347d984975d0592e42f05",
            6: "f2a5fbc7089e4e6aa0300b88159d97b3",
            18: "63927f0434a04d4d95d7713e0266a2aa",
            hf: "716e9c460ced41ffa371075f7b9446ec"
        };
        return d.kta.clickStat(t[e]);
    },
    recordPage: function() {
        var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "190", t = {
            190: "55205d3cfb034e94adaab2f532d82a44",
            6: "ed8cd63b41f84945ac49caf59c3d6516",
            18: "86bcfd9cf33440c08dff93c42f685e34",
            hf: "758058aa4b194d268b83279be3f9cfca"
        };
        return d.kta.clickStat(t[e]);
    },
    modalBtn: function() {
        return d.kta.clickStat("901598261e5444688a324d209e055de2");
    },
    headerBtn: function() {
        return d.kta.clickStat("a7dd1a59c3e745ef85890e1d22357287");
    }
};

exports.ktaUtil = u;

var f = function() {
    function e(t) {
        a(this, e), this.opt = t, this.factor = 1, this.CanvasWidth = 375, this.CanvasHeight = 667, 
        this.vm = t.vm, this.type = t.type, this.inviteUrl = t.inviteUrl || "", this.windowWidth = 0, 
        this.bgTempPath = null, this.picHasSaved = !1, this.poster = null, this.userInfo = {
            nickName: t.nickname || "",
            avatarUrl: null
        }, this.postStyleType = this.checkPosterType(this.type), this.posterUrlArray = [ s.imageBaseUrl.YQYL_new + "poster.png", s.imageBaseUrl.YQYL2 + "poster1.png", s.imageBaseUrl.YQYL_hf + "poster.png" ], 
        this.postBgUrl = this.posterUrlArray[this.postStyleType], this.init();
    }
    return n(e, [ {
        key: "checkPosterType",
        value: function(e) {
            if ("190" === e || "record" === e || "18" === e || "record18" === e || "dl" === e) return 0;
            if ("6" === e || "spreadRecord" === e) return 1;
            if ("hf" === e) return 2;
            throw new Error("无法识别的海报类型");
        }
    }, {
        key: "init",
        value: function() {
            return Promise.all([ this.getWindowSize(), this.getBgTempPath(), this.getUserAvatar() ]);
        }
    }, {
        key: "getLocalPath",
        value: function(e) {
            return new Promise(function(t, a) {
                wx.getImageInfo({
                    src: e,
                    success: function(e) {
                        e.path && e.width > 0 && e.height > 0 ? t(e.path) : (wx.showModal({
                            content: "获取图片临时地址失败，尺寸或者路径错误",
                            showCancel: !1
                        }), a());
                    },
                    fail: function(e) {
                        r.default.toast("获取图片临时路径失败"), a(e);
                    }
                });
            });
        }
    }, {
        key: "getWindowSize",
        value: function() {
            var e = this;
            return new Promise(function(t, a) {
                0 !== e.windowWidth ? t(e.windowWidth) : wx.getSystemInfo({
                    success: function(a) {
                        e.windowWidth = a.windowWidth, e.factor = e.windowWidth / 375, e.CanvasWidth = 375 * e.factor, 
                        e.CanvasHeight = 667 * e.factor, t(a.windowWidth);
                    },
                    fail: function() {
                        r.default.toast("获取系统信息失败"), a();
                    }
                });
            });
        }
    }, {
        key: "getBgTempPath",
        value: function() {
            var e = this;
            return new Promise(function(t) {
                e.bgTempPath ? t(e.bgTempPath) : e.getLocalPath(e.postBgUrl).then(function(a) {
                    e.bgTempPath = a, t(a);
                });
            });
        }
    }, {
        key: "getUserAvatar",
        value: function() {
            var e = this;
            return new Promise(function(t) {
                e.userInfo.avatarUrl || 1 === e.postStyleType ? t(e.userInfo.avatarUrl) : e.getLocalPath(s.imageBaseUrl.YQYL + "homePage2.png").then(function(a) {
                    e.userInfo.avatarUrl = a, t(a);
                });
            });
        }
    }, {
        key: "handleSharePoster",
        value: function() {
            var e = this;
            return u.poster(this.type), wx.showLoading({
                title: "分享海报生成中..."
            }), this.init().then(function() {
                return e.drawPoster();
            });
        }
    }, {
        key: "drawPoster",
        value: function() {
            var e = this, t = wx.createCanvasContext("poster", this.vm);
            if (0 === this.postStyleType) {
                var a = 150 * this.factor, n = 110 * this.factor, r = 294 * this.factor, i = a - 20, o = n + 10, s = r + 10;
                c.default.qrcode("qrcode", this.inviteUrl, 500, 500, function(c, l) {
                    wx.canvasToTempFilePath({
                        canvasId: "qrcode",
                        x: c,
                        y: c,
                        width: l,
                        height: l,
                        success: function(c) {
                            e.CanvasHeight = 646 * e.factor, t.drawImage(e.bgTempPath, 0, 0, e.CanvasWidth, e.CanvasHeight), 
                            t.drawImage(e.userInfo.avatarUrl, 23, 21, 44, 44), t.setFillStyle("white"), t.fillRect(n, r, a, a), 
                            t.drawImage(c.tempFilePath, o, s, i, i), t.setFillStyle("#fff"), t.setFontSize(18), 
                            t.fillText(e.userInfo.nickName, 80, 40), t.setFontSize(14), t.fillText("邀你用王卡", 80, 62), 
                            t.save(), e.drawDone(t);
                        }
                    }, e.vm);
                });
            }
            if (1 === this.postStyleType) {
                var l = 150 * this.factor, d = 110 * this.factor, u = 200 * this.factor;
                c.default.qrcode("qrcode", this.inviteUrl, 500, 500, function(a, n) {
                    wx.canvasToTempFilePath({
                        canvasId: "qrcode",
                        x: a,
                        y: a,
                        width: n,
                        height: n,
                        success: function(a) {
                            var n = 0 | e.vm.data.result.reward_count, r = 6 * n.toString().length;
                            e.CanvasHeight = 747 * e.factor, t.drawImage(e.bgTempPath, 0, 0, e.CanvasWidth, e.CanvasHeight);
                            t.setFillStyle("#000"), t.setFontSize(19), t.setTextAlign("center");
                            var i = e.windowWidth / 2;
                            t.fillText("我邀请好友用腾讯王卡", i, 140), t.fillText("已经获得", i - 50 - r, 172), t.setFillStyle("#E80526"), 
                            t.fillText("".concat(n, "元"), i, 172), t.setFillStyle("#000"), t.fillText("现金红包", i + 50 + r, 172);
                            var o = 402 * e.factor;
                            t.setFillStyle("#323232"), t.setFontSize(16), t.fillText("立即扫码参与", i, o), t.fillText("和我一起轻松赚钱", i, o + 30), 
                            t.drawImage(a.tempFilePath, d, u, l, l), t.save(), e.drawDone(t);
                        }
                    }, e.vm);
                });
            }
            if (2 === this.postStyleType) {
                var f = 170 * this.factor, h = 103 * this.factor, g = 380 * this.factor, p = f - 20, v = h + 10, w = g + 10;
                c.default.qrcode("qrcode", this.inviteUrl, 500, 500, function(a, n) {
                    wx.canvasToTempFilePath({
                        canvasId: "qrcode",
                        x: a,
                        y: a,
                        width: n,
                        height: n,
                        success: function(a) {
                            e.CanvasHeight = 747 * e.factor, t.drawImage(e.bgTempPath, 0, 0, e.CanvasWidth, e.CanvasHeight), 
                            t.drawImage(e.userInfo.avatarUrl, 18, 8, 44, 44), t.setFillStyle("white"), t.fillRect(h, g, f, f), 
                            t.drawImage(a.tempFilePath, v, w, p, p), t.save(), e.drawDone(t);
                        }
                    }, e.vm);
                });
            }
        }
    }, {
        key: "drawDone",
        value: function(e) {
            var t = this;
            e.draw(!1, function() {
                wx.canvasToTempFilePath({
                    canvasId: "poster",
                    success: function(e) {
                        t.vm.setData({
                            poster: e.tempFilePath,
                            showPoster: !0
                        }), t.poster = e.tempFilePath, t.savePoster();
                    },
                    complete: function() {
                        wx.hideLoading();
                    }
                }, t.vm);
            });
        }
    }, {
        key: "savePoster",
        value: function() {
            var e = this;
            this.poster && !this.picHasSaved && wx.saveImageToPhotosAlbum({
                filePath: this.poster,
                success: function() {
                    wx.showToast({
                        title: "分享海报已保存，快去分享给好友吧。",
                        icon: "none"
                    }), e.picHasSaved = !0;
                },
                fail: function() {
                    wx.showModal({
                        content: "保存失败，请授权允许使用我的相册",
                        showCancel: !1,
                        success: function() {
                            wx.openSetting({
                                success: function(t) {
                                    t.authSetting["scope.writePhotosAlbum"] ? e.savePoster() : wx.showModal({
                                        content: "您没有打开保存相册功能，不能保存图片哦~点击右上角设置允许访问相册",
                                        showCancel: !1
                                    });
                                },
                                fail: function() {
                                    r.default.toast("打开设置失败");
                                }
                            });
                        }
                    });
                }
            });
        }
    } ]), e;
}();

exports.SharePoster = f;

var h = function(e, t) {
    var a = i.default;
    return "hf" === t && (a = o.default), a.getUserInfo().then(function(a) {
        var n = a.activity_info || a.result;
        if ("hf" !== t) {
            var r = n.end_time - Date.now();
            r < 0 && (r = 1), n.invite_rewarded_count = (n.invite_rewarded_count / 100).toFixed(2), 
            e.setData({
                time: r
            });
        }
        return e.setData({
            activity_info: n
        }), n;
    });
};

function g(e, t) {
    if (e[t]) return e[t];
    if (e.q) {
        var a = decodeURIComponent(e.q);
        if ((0, l.getQueryStringFromQrCode)(a, t)) return (0, l.getQueryStringFromQrCode)(a, t);
    }
    return "";
}

exports.getUserInfo = h;

var p = 864e5, v = p / 24, w = v / 60, m = w / 60;